/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control.thuoc;

import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import model.entity.Thuoc;

/**
 *
 * @author luanp_000
 */
public class Thuoc_ctrl {

    public static void timKiemTableFiller(JTable jTable, List<Thuoc> list) {
        if (list == null) {
            JOptionPane.showMessageDialog(null, "Không tìm thấy kết quả nào.");
            return;
        }
        DefaultTableModel model = (DefaultTableModel) jTable.getModel();

        //clear table
        int rowCount = model.getRowCount();
        for (int i = rowCount - 1; i >= 0; i--) {
            model.removeRow(i);
        }
        //insert items from list
        for (Thuoc thuoc : list) {
            model.addRow(new Object[]{thuoc.getThuocMa(), thuoc.getThuocTen(), thuoc.getNhaCungCap()});
        }
        list.removeAll(list);
    }

    public static void mainpanelTableFiller(JTable jTable, List<Thuoc> list) {
        if (list == null) {
            JOptionPane.showMessageDialog(null, "Không tìm thấy kết quả nào.");
            return;
        }
        DefaultTableModel model = (DefaultTableModel) jTable.getModel();

        //clear table
        int rowCount = model.getRowCount();
        for (int i = rowCount - 1; i >= 0; i--) {
            model.removeRow(i);
        }
        //insert items from list
        for (Thuoc thuoc : list) {
            model.addRow(new Object[]{thuoc.getThuocMa(), thuoc.getThuocTen(), thuoc.getGia().getGiaGoc(), thuoc.getGia().getGiaBan(), thuoc.getNhaCungCap(), thuoc.getSoLuong()});
        }
        list.removeAll(list);
    }
}
